package com.qf.flash.ui.circle.adapter;

import android.content.Context;
import android.view.View;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.qf.flash.R;
import com.qf.flash.app.MyApp;
import com.qf.flash.model.CapacityBean;
import com.qf.flash.model.CapacityRankThreeBean;
import com.qf.flash.model.ListTopBean;
import com.qf.flash.ui.business.OrderDetailActivity;
import com.qf.flash.ui.home.MemberMsgActivity;
import com.qf.flash.widget.CircleImageView;
import com.qf.flashlib.adapter.BaseRViewItem;
import com.qf.flashlib.adapter.RViewHolder;

public class ListTopItem extends BaseRViewItem<Object> {
    private Context context;

    public ListTopItem(Context context) {
        this.context = context;
    }

    @Override
    public boolean isItemView(Object entity, int position) {
        return entity instanceof CapacityRankThreeBean;
    }

    @Override
    public int getItemLayout() {
        return R.layout.item_list_top;
    }

    @Override
    public void convert(RViewHolder holder, Object entity, int position, int itemSize) {
        CapacityRankThreeBean capacityRankThreeBean = (CapacityRankThreeBean) entity;

        CircleImageView headFirst = holder.getView(R.id.header_first);
        CircleImageView headSecond = holder.getView(R.id.header_second);
        CircleImageView headThird = holder.getView(R.id.header_third);

        for (int i = 0; i < capacityRankThreeBean.capacityBeans.size(); i++) {
            switch (i) {
                case 0:
                    Glide.with(context).load(capacityRankThreeBean.capacityBeans.get(0).getPhoto())
                            .apply(new RequestOptions().error(R.mipmap.default_avatar).placeholder(R.mipmap.default_avatar))
                            .into(headFirst);
                    holder.setText(R.id.tv_one, capacityRankThreeBean.capacityBeans.get(0).getCount() + "次");
                    holder.setText(R.id.tv_first_name, capacityRankThreeBean.capacityBeans.get(0).getName());
                    headFirst.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            MemberMsgActivity.start(holder.getmConvertView().getContext(), capacityRankThreeBean.capacityBeans.get(0).getId(), "");
                        }
                    });
                    break;
                case 1:
                    Glide.with(context).load(capacityRankThreeBean.capacityBeans.get(1).getPhoto())
                            .apply(new RequestOptions().error(R.mipmap.default_avatar).placeholder(R.mipmap.default_avatar))
                            .into(headSecond);
                    holder.setText(R.id.tv_two, capacityRankThreeBean.capacityBeans.get(1).getCount() + "次");
                    holder.setText(R.id.tv_second_name, capacityRankThreeBean.capacityBeans.get(1).getName());
                    headSecond.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            MemberMsgActivity.start(holder.getmConvertView().getContext(), capacityRankThreeBean.capacityBeans.get(1).getId(), "");
                        }
                    });
                    break;
                case 2:
                    Glide.with(context).load(capacityRankThreeBean.capacityBeans.get(2).getPhoto())
                            .apply(new RequestOptions().error(R.mipmap.default_avatar).placeholder(R.mipmap.default_avatar))
                            .into(headThird);
                    holder.setText(R.id.tv_three, capacityRankThreeBean.capacityBeans.get(2).getCount() + "次");
                    holder.setText(R.id.tv_third_name, capacityRankThreeBean.capacityBeans.get(2).getName());
                    headThird.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            MemberMsgActivity.start(holder.getmConvertView().getContext(), capacityRankThreeBean.capacityBeans.get(2).getId(), "");
                        }
                    });
                    break;
            }
        }

    }
}
